{extend name="layouts/app"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">编辑后台菜单</div>
    <div class="layui-card-body">
        <form class="layui-form" method="post" action="{:url('update')}">
            <div class="layui-form-item">
                <label class="layui-form-label">上级菜单</label>
                <div class="layui-input-inline w300">
                    <cascader id="menu"></cascader>
                    <input type="hidden" name="parent_id" value="{$menu->parent_id}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">名称 </label>
                <div class="layui-input-inline w300">
                    <input type="text" name="title" value="{$menu->title}" lay-verify="required" autocomplete="off" placeholder="名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-block">
                    <input type="text" id="iconPicker" value="{$menu->icon}" lay-filter="iconPicker" class="hide" name="icon">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">模块</label>
                <div class="layui-input-inline w300">
                    <input type="text" name="app" value="{$menu->app}" lay-verify="required" autocomplete="off" placeholder="模块" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">控制器</label>
                <div class="layui-input-inline w300">
                    <input type="text" name="controller" value="{$menu->controller}" lay-verify="required" autocomplete="off" placeholder="控制器" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">方法</label>
                <div class="layui-input-inline w300">
                    <input type="text" name="action" value="{$menu->action}" lay-verify="required" autocomplete="off" placeholder="方法" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">附加参数</label>
                <div class="layui-input-inline w300">
                    <input type="text" name="parameter" value="{$menu->parameter}" autocomplete="off" placeholder="附加参数" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否显示</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="是" {eq name="$menu->status" value="1" }checked{/eq} >
                    <input type="radio" name="status" value="0" title="否" {eq name="$menu->status" value="0" }checked{/eq} >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否目录</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_directory" value="1" title="是" {eq name="$menu->is_directory" value="1" }checked{/eq} >
                    <input type="radio" name="is_directory" value="0" title="否" {eq name="$menu->is_directory" value="0" }checked{/eq} >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否菜单</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_menu" value="1" title="是" {eq name="$menu->is_menu" value="1" }checked{/eq} >
                    <input type="radio" name="is_menu" value="0" title="否" {eq name="$menu->is_menu" value="0" }checked{/eq} >
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{$menu->id}">
                    <button class="layui-btn" lay-submit="" lay-filter="formSubmit">立即提交</button>
                    <button class="layui-btn layui-btn-normal" type="button" onclick="javascript:history.back(-1);">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.extend({
        ajaxCascader: 'ajaxCascader/ajaxCascader',
    }).use(['iconPicker', 'form', 'layer','ajaxCascader'], function () {
        var iconPicker = layui.iconPicker,
            form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            ajaxCascader=layui.ajaxCascader;

        //选择菜单
        ajaxCascader.load({
            elem: '#menu'
            ,search: {
                show: true,
                minLabel: 10,
                placeholder: '请输入搜索词'
            }
            ,clear: true
            ,value: 0
            ,chooseData:<?php echo $chooseData; ?>
            ,getChildren: function(value,callback){
                var data = [];
                $.ajax({
                    url:"{:url('apiGetMenu')}",
                    type:'get',
                    data:{parent_id:value},
                    success:function(res){
                        data = res.data;
                        for(var i in data){
                            data[i].value = data[i].id;
                            data[i].label = data[i].title;
                            delete data[i].id;
                            delete data[i].title;
                            data[i].hasChild = data[i].is_directory;
                        }
                        callback(data);
                    }
                });
            }
        });
        ajaxCascader.on('click', '#menu', function(data){
            $("input[name='parent_id']").val(data.value);
        });

        //选择图标
        iconPicker.render({
            // 选择器，推荐使用input
            elem: '#iconPicker',
            // 数据类型：fontClass/unicode，推荐使用fontClass
            type: 'fontClass',
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {

            },
            // 渲染成功后的回调
            success: function(d) {

            }
        });



    });
</script>
{/block}